import dialogForm from './edit'              //弹窗组件
import agentHttp from '@/utils/agentHttp'    //请求方法
import pagination from '@/views/pagination'  //分页组件
import {confirm} from '@/utils/confirm'      //二次确认组件
import {debounce} from '@/utils/index.js'
export default {
  name: 'user',
  created(){
     this.seachData()
  },
  components:{dialogForm,pagination},
  data() {
  	return {
      searchForm:{
        roleName:"",
        type:"",
        realname:"",
        username:""
      },
  		tableData: [{
          px: '9',
          rmpp: '玛莎拉蒂'         
        }],
      //弹窗状态数据
      dialogSendData:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      options: [{
        value: '品牌1',
        label: '品牌1'
      }],
      userTypeArray:  { 0:'链上车用户',1:'资金方',2:'SPV',3:'链上车SPV' }  ,
      resetFormStatus:false
  	}
  },
  methods: {
    //重置
    resetSearchForm(formName){
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //查看
    seachData(){  
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.post('adminApi/admin/user/query_user_and_role_list',params ).then((data)=>{
              this.tableData = data;
        })
    
    },
    //延迟搜索
    debounceSeach(){  
      debounce(this.seachData(),1000)
    },
    /*表格操作按钮*/
    //删除
    handleDel(index, row){

        confirm(()=>{
          agentHttp.del('adminApi/admin/user/delete/'+row.id).then((data)=>{
            if(data.success){  
                this.$message.success(data.data);
                this.seachData();
                //这里编写数据赋值或者其他逻辑  例如：this.tableData = data;
            } 
          })
        },()=>{
           this.$message.info('已取消删除'); 
        },"确认删除该条数据吗?")
    },
    //启用/禁用
     handleDisable(  row){   
          var messages = "启用";
         if( row.enable ){
          row.enable = 1;
          messages = "停用";
         }else {
          row.enable = 0;
         } 
        confirm(()=>{
           agentHttp.put('adminApi/admin/user/enable_user/'+row.id+'/'+row.enable).then((data)=>{
            if(data.success){  
                this.$message.success(data.data);
                this.seachData(); 
            } 
          })
        },()=>{ 
        },"确认"+messages+"该条数据吗?") 
    },
    //新增、编辑
    handleEdit(index, row){ 
      row?this.dialogSendData.id=row.id:this.dialogSendData.id="";
      this.dialogSendData.isAdd=true;  
      this.dialogSendData.dialogFormVisible=true;
    }
  }
}